package com.hyperf.event.client.impl;

import com.hyperf.event.client.EventAction;
import com.hyperf.event.client.EventListenerService;
import com.hyperf.event.client.EventMessage;
import com.hyperf.event.client.EventMessageListener;

/**
 * @author lizhaoyang
 */
public class EventListenerServiceImpl extends AbstractEventListenerService implements EventListenerService {

    @Override
    public EventAction consume(EventMessage message) {
        String type = message.getType();
        EventMessageListener eventMessageListener;

        if (eventListenerMap.containsKey(type)) {
            eventMessageListener = eventListenerMap.get(type);
        } else {
            return EventAction.RECONSUME_LATER;
        }

        try {
            return eventMessageListener.consume(message);
        } catch (Throwable throwable) {
            return EventAction.RECONSUME_LATER;
        }
    }
}
